package studio.raptor.ddal.core.log.queue;

import java.util.AbstractQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * java jvm 队列
 */
public class JavaQueue {

	private  BlockingQueue logQueue = new LinkedBlockingQueue();
//	private AbstractQueue logQueue = new ConcurrentLinkedQueue();

	/**
	 * 读取对象
	 * @return
	 * @throws InterruptedException
	 */
	public Object take() throws InterruptedException{
		//take 移除并返回队列头部的元素；如果队列为空，则阻塞
		return logQueue.take();
	}

	/**
	 * 获取队列当前size
	 * @return
	 */
	public int getDepth(){
		return logQueue.size();
	}

	/**
	 * 添加对象
	 * @param logModel
	 * @return
	 */
	public  boolean addObj(Object logModel) {
		//add 增加一个元索；如果队列已满，则抛出一个IllegalStateException异常
		return logQueue.add(logModel);
	}

}
